package ute.mvc.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
public class OpenCourse implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8732612360071041002L;

	@Id
	@Column(length = 20)
	private String openCourseId;

	@ManyToOne
	@JoinColumn(name = "courseId", nullable = false)
	private Course course;

	@NotNull
	@DateTimeFormat(pattern = "dd/MM/yyyy")
	@Temporal(TemporalType.DATE)
	private Date startDay;

	// Vinh
	@JsonIgnore
	@Transient
	private List<Subject> listSubject = new ArrayList<Subject>();

	@JsonIgnore
	@ManyToMany
	@JoinTable(name = "openCourse_Lecturer", joinColumns = @JoinColumn(name = "openCourseId"), inverseJoinColumns = @JoinColumn(name = "userId"))
	private Collection<User> listLecturer = new ArrayList<User>();

	private boolean isEnd;

	@Column(length = 10000)
	private String description;

	@JsonIgnore
	@OneToMany(mappedBy = "openCourse", fetch = FetchType.LAZY)
	private Collection<MyClass> listClass = new ArrayList<MyClass>();

	@JsonIgnore
	@OneToMany(mappedBy = "openCourse")
	private Collection<OpenCourse_Subject> listCourse_Subject = new ArrayList<OpenCourse_Subject>();

	public List<Subject> getListSubject() {
		return listSubject;
	}

	public void setListSubject(List<Subject> listSubject) {
		this.listSubject = listSubject;
	}

	public Collection<User> getListLecturer() {
		return listLecturer;
	}

	public void setListLecturer(Collection<User> listLecturer) {
		this.listLecturer = listLecturer;
	}

	public Collection<OpenCourse_Subject> getListCourse_Subject() {
		return listCourse_Subject;
	}

	public void setListCourse_Subject(
			Collection<OpenCourse_Subject> listCourse_Subject) {
		this.listCourse_Subject = listCourse_Subject;
	}

	public Collection<MyClass> getListClass() {
		return listClass;
	}

	public void setListClass(Collection<MyClass> listClass) {
		this.listClass = listClass;
	}

	@NotEmpty
	public String getOpenCourseId() {
		return openCourseId;
	}

	public void setOpenCourseId(String openCourseId) {
		this.openCourseId = openCourseId;
	}

	public Course getCourse() {
		return course;
	}

	public void setCourse(Course course) {
		this.course = course;
	}

	public Date getStartDay() {
		return startDay;
	}

	public void setStartDay(Date startDay) {
		this.startDay = startDay;
	}

	public boolean isEnd() {
		return isEnd;
	}

	public void setEnd(boolean isEnd) {
		this.isEnd = isEnd;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
}
